|
In computer programming, the binary operator ?: colloquially referred to as the Elvis operator due to its resemblance to an emoticon, is a shorthand binary variant of the ternary conditional operator in languages such as PHP〔https://github.com/getrailo/railo/wiki/Operators#elvis-operator〕 and Groovy. It is used by several other languages that use the ? : operator, which is the most common ternary operator.〔(【引用サイトリンク】title=What is the PHP ? : operator called and what does it do? )〕Binary ?: , used as an operator with two arguments around it and no characters in between, is used to obtain a value that is specified in the second argument if the first argument is false, and to return the value of the first argument otherwise.An Elvis operation can be understood to represent a ?: ternary operation with the second argument omitted and assumed to equal the first.For example, var = foo ?: bar contains the expression foo ?: bar which evaluates to foo if foo exists and has a non-null value, then var = foo ; otherwise var = bar .==Syntax== (詳細はnull coalescing operator, this is a compression of the ternary conditional statement: Or, expanded into an if-then statement: It is useful for writing short conditional statements that depend on the value of a variable without changing the unspecified value (if it exists), and to avoid returning an error if the value of the condition is not set. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Elvis operator」の詳細全文を読む スポンサード リンク
|